package cz.muni.fi.pa165.sme.web.converters;

import cz.muni.fi.pa165.sme.api.to.SportActivityRecordTO;
import cz.muni.fi.pa165.sme.web.common.DateUtils;
import cz.muni.fi.pa165.sme.web.fo.SportActivityRecordFO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;

/**
 * @author jirankova
 */
public class SportActivityRecordFO2SportActivityRecordTOConverter implements
		Converter<SportActivityRecordFO, SportActivityRecordTO> {

	@Autowired
	private SportActivityFO2SportActivityTOConverter sportActivityTOConverter;

	@Autowired
	private UserFO2UserTOConverter userTOConverter;

	@Override
	public SportActivityRecordTO convert(final SportActivityRecordFO source) {
		if (source == null) {
			return null;
		}

		final SportActivityRecordTO activityRecordTO = new SportActivityRecordTO();

		activityRecordTO.setActivityStart(DateUtils.convertToDateTime(source.getActivityStart()));
		activityRecordTO.setActivityStop(DateUtils.convertToDateTime(source.getActivityStop()));
		activityRecordTO.setDistance(source.getDistance());
		activityRecordTO.setDuration(source.getDuration());
		activityRecordTO.setId(source.getId());
		activityRecordTO.setSportActivity(sportActivityTOConverter.convert(source.getSportActivity()));
		activityRecordTO.setUser(userTOConverter.convert(source.getUser()));

		return activityRecordTO;
	}
}
